<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 新增文章 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-article"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm">
				<form class="form-horizontal form-editor form-editor-article">
					<div class="row">
					
						<div class="col-sm-8">
							<div class="form-group">
								<label class="col-sm-2 control-label required" for="title">标题</label>
								<div class="col-sm-10">
									<input name="title" id="title" type="text" class="form-control" required="required">
									
								</div>
							</div>
						</div>
						
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label required" for="articleType">类型</label>
								<div class="col-sm-8">
									<select name="articleType" id="articleType" class="chosen-select"> 
										<option value="育儿宝典">育儿宝典</option>
										<option value="热门活动">热门活动</option>
									</select>
								</div>
							</div>
						</div>
						
						
					</div>
					
					<div class="row">
					
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="createTime">发布时间</label>
								<div class="col-sm-8">
									<div class="input-group date date-selector">
										<input name="createTime" id="createTime" type="text" class="form-control"> 
										<span class="input-group-addon">
											<span class="fa fa-calendar"></span>
										</span>
									</div>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="shopId">发布机构</label>
								<div class="col-sm-8">
									<select name="shopId" id="shopId" class="chosen-select" onchange="getAuthor()">
	              	</select>
	              </div>
	     				</div>
     				</div> 
     				
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="authorId">发布人</label>
								<div class="col-sm-8">
									<select name="authorId" id="authorId" class="chosen-select">
										<option >请选择发布人</option>
	              	</select>
	              </div>
	     				</div>
     				</div> 
     				
					</div>
					
					<div class="row">
             <div class="col-sm-8">
							<div class="widget-header bordered-top ">
								<span class="widget-caption "> <font color="#f85d2c">文章摘要 (APP首页展示需要,必须填写)</font> </span>
							</div>
							<div class="widget-body">
								<textarea id="summary" name="summary"  class="form-control" required="required" rows="8" maxlength="50" placeholder="可输入50字" ></textarea>
							</div>
						</div>
						
						<div class="col-sm-4">
							<div class="widget-header bordered-top ">
								<span class="widget-caption"> <font >首页图片 (APP首页展示需要)</font> </span>
							</div>
						
							<div class="widget-body" style="width: 100%; height: 197px;">
								<input name="pictures" type="hidden">
								<a href="javascript:void(0);"  onclick="handlerModal(this, 'content/system/content/article/dialog/pictures.html', 'createPictures', 'destroyPictures');">
									<img src="/miwawa/resources/photos/web/empty.png" width="100%" height="100%" id="_img">
								</a>
							</div>	
						</div>
	
					</div>
										
					<p></p>	
				
					<div class="row">
						<div class="col-sm-8">
							<div class="widget">
								<div class="widget-header bordered-top ">
									<span class="widget-caption"> 文章内容</span>

								</div>
								<div class="widget-body">
									<textarea id="content" name="content" class="form-control" ></textarea>
								</div>
							</div>
						</div>
						
						<div class="col-sm-4" >
							<div class="widget">
								<div class="widget-header bordered-top ">
									<span class="widget-caption"> 手机预览效果</span>
								</div>
								<div class="widget-body"  >
									<div id="preview" style="width:100%; height:568px; position:relative; background: url('/miwawa/resources/photos/web/mobile.png') center center;background-size:100% 100%;" >
										<div id="contentPreview" style="position:absolute;top:76px;left:20px;bottom:76px;right:20px;word-wrap:break-word;overflow-y:auto; ">									
										
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					
					<div class="widget-footer editor-footer-sm">
						<button type="button" class="btn btn-danger btn-sm" 
						data-toggle="tooltip" data-placement="top" title="取消" 
						onclick="handlerCancel(this);" data-refresh-table="#table-article">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" 
						data-toggle="tooltip" data-placement="top" title="保存"
						onclick="handlerSubmit(this, '#editor-form-article', '.form-editor-article','getSrc');">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
				</form>
			</div>
		</div>
		
		
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-article" action="/miwawa/default/common/save" method="post" 
			name="com.app.miwawa.api.system.entity.Article" >
			<input type="hidden" name="bean['status']" value="0">
			<input type="hidden" name="bean['invalid']" value="F">
</form>

<script type="text/javascript">
<!--
	var src = [];
	var article;
	jQuery(function() {
		getShops();
		getAuthor();
		Preview();
		require(['moment','jquery.plugin.form'],function(moment, form){
			form.tooltip("[data-toggle='tooltip']");
			form.datepicker('.date-selector',{format:"YYYY-MM-DD HH:mm"});
			form.chosen("#articleType").select("#articleType",null,function(chosen){
			});
			form.chosen("#shopId").select("#shopId",null,function(chosen){
			});
			
			// 注册富文本编辑器控件
			form.summernote("#content",{
					toolbar:[    
					   ['fontsize', ['fontsize']] ,
					   ['fontname', ['fontname']],
					   ['style', ['bold', 'italic', 'underline', 'clear']],
					   ['color', ['color']],
					   ['picture', ['picture']],
					   ['link', ['link']],
					   ['table', ['table']],
					   ['para', ['ul', 'ol', 'paragraph','height']],
					   ['fullscreen', ['fullscreen']],
					   ['codeview', ['codeview']],
					   ['undo', ['undo']],
					   ['help', ['help']],
					],
					height:462,
					callbacks: {
			   		onImageUpload: function(files) {
			    		uploadFile(files[0]);
			    	}
			  	}
			});
		});
	});
	
	//上传文件
	function uploadFile(file){
		var data = new FormData();
	      data.append("file", file);
	      data.append("type", "image");
	      data.append("mode", "file");
	      data.append("group", "article");
	      data.append("notsaved", true);
	      
	  jQuery.ajaxsend({
		  url: "/miwawa/{dbname}/file/upload".replace("{dbname}", dbname),
		  data: data,
		  contentType: false,
	    processData: false,
		  success: function(file){
	    	jQuery("#content").summernote('insertImage', file.url ,function(image){
	    		image.css('width' , '100%');
	    	});
	    	src.push(file.url);
		  }
	  });
	}
	
	//获取机构列表
	function getShops() {
    jQuery.ajaxsend({
        url:"/miwawa/default/common/search.json",
        data:{
            "entityClass":"com.app.miwawa.api.system.entity.view.ShopView",
            "and[0][operator]":"EQ",
            "and[0][fieldName]":"invalid",					// 删除标识
            "and[0][fieldValue]":"F",						// F=有效的<未删除>、T=无效的<已删除>
            "and[1][operator]":"EQ",
            "and[1][fieldName]":"status",					// 状态标识
            "and[1][fieldValue]":"0",						// 默认为0
            "and[2][operator]":"EQ",
            "and[2][fieldName]":"dbname",					    // 早教中心数据源
            "and[2][fieldValue]":dbname	// dbname
        },
        async:false,
        success : function(data) {
           var inner='';
           var dataList=data.rows;
           for(var i=0;i<dataList.length;i++){
               inner+='<option value="'+dataList[i].id +'">'+dataList[i].name+'</option>';
           }
           $("#shopId").html(inner);
        }
    });
	}
	
	function getAuthor(){
		jQuery.ajaxsend({
       url:"/miwawa/default/common/search.json",
       data:{
           "entityClass" : "com.app.miwawa.api.system.entity.view.Account",
           "and[0][operator]": "EQ",
           "and[0][fieldName]": "invalid",					// 删除标识
           "and[0][fieldValue]": "F",						// F=有效的<未删除>、T=无效的<已删除>
           "and[1][operator]": "EQ",
           "and[1][fieldName]": "status",					// 状态标识
           "and[1][fieldValue]": "0",						// 默认为0
           "and[2][operator]": "EQ",
           "and[2][fieldName]": "shopsid",			// 机构id
           "and[2][fieldValue]": $("#shopId").val()// 
       },
       async:false,
       success:function(data) {
          var inner='';
          var dataList=data.rows;
          for(var i=0;i<dataList.length;i++){
              inner+='<option value="'+dataList[i].id +'">'+dataList[i].name+'</option>';
          }
          $("#authorId").html(inner);
       }
		});
		require(['jquery.plugin.form'],function(form){
			form.chosen("#authorId").select("#authorId",null,function(chosen){
				
			});
		});
	}
	
	function getSrc(){
		/* var a= jQuery("#content",'.form-editor-article').val();
		var b= /src=\".*?\"/gi;
		var s = a.match(b);
		if(s != null){
			var reg = new RegExp("src=","g");
			var arr= s.toString().replace(reg,"");
			var reg2 = new RegExp("\"","g");
			var arr2= arr.replace(reg2,"");
			jQuery("#pictures",'#editor-form-article').val(arr2);
		}else{
			jQuery("#pictures",'#editor-form-article').val("http://www.honeykids.com.cn/miwawa/resources/photos/web/empty.png");
		} */
		jQuery("#pictures",'#editor-form-article').val($("#_img").attr("src"));
		return true;
	}
	
	function Preview(){
		var contents = jQuery("#content",'.form-editor-article').val();
		jQuery("#contentPreview").html(contents);
		window.setTimeout("Preview()",100);
	}
	
//-->
</script>